﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AutoMapper;
using mtg_trader.Database;
using mtg_trader.Database.DbSets;
using mtg_trader.Web.Models.Home;

namespace mtg_trader.Web.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Card(string cardTerm)
        {

            Mapper.CreateMap<Card, CardModel>();

            CardModel cardModel;

            using (var context = new MtgContext())
            {
                var card  = context.Cards.FirstOrDefault(c => c.Id == cardTerm) ??
                            context.Cards.FirstOrDefault(c => c.Name == cardTerm);

                cardModel = Mapper.Map<CardModel>(card);
            }
            return View(cardModel);

        }

    }
}
